<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./js/jquery.min.js"></script>
    <script src="./js/jquery.form.js"></script>
</head>
<body>
<form id="mainForm" action="/trainExam/rest/menus/85" method="POST">
    <div>id:</div><input type="text" id="id" name="id"></br>
    <div>fatherId:</div><input type="text" id="fatherId" name="fatherId"></br>
    <div>types:</div><input type="radio" name="types" value="2" checked="checked">菜单<input type="radio" value="1" name="types" >功能<input type="radio" value="0" name="types" >请求</br>
    <div>isMobile:</div><input type="text" id="isMobile" name="isMobile"></br>
    <div>isWeb:</div><input type="text" id="isWeb" name="isWeb"></br>
    <div>frontName:</div><input type="text" id="frontName" name="frontName"></br>
    <div>fatherLink:</div><input type="text" id="frontLink" name="frontLink"></br>
    <div>backName:</div><input type="text" id="backName" name="backName"></br>
    <div>backLink:</div><input type="text" id="backLink" name="backLink"></br>
    <div>bigImage:</div><input type="text" id="bigImage" name="bigImage"></br>
    <div>middleImage:</div><input type="text" id="middleImage" name="middleImage"></br>
    <div>smallImage:</div><input type="text" id="smallImage" name="smallImage"></br>
    <div>order:</div><input type="text" id="order" name="order" value="0"></br>

</form>
<input id="btn_submit" type="button" value="提交">
<script type="text/javascript">
    jQuery(document).ready(function ($) {
        let url = decodeURI(window.location.href);
        let argsIndex = url .split("?id=");

        if (argsIndex.length = 2) {
            let arg = argsIndex[1];
            $.ajax({
                url: "/trainExam/rest/menus/" + arg,
                type: "get",
                dataType: "json",
                success: function (data) {
                    if (data !== undefined) {//检测返回的值是否为空
                        if (data.success) {
                            let menu = data.data;
                            $("#id").val(menu.id);
                            $("#fatherId").val(menu.fatherId);
                            $(":radio[name='types'][value='" + menu.types + "']").prop("checked", "checked");
                            $("#isMobile").val(menu.isMobile);
                            $("#isWeb").val(menu.isWeb);
                            $("#frontName").val(menu.frontName);
                            $("#frontLink").val(menu.frontLink);
                            $("#backName").val(menu.backName);
                            $("#backLink").val(menu.backLink);
                            $("#bigImage").val(menu.bigImage);
                            $("#middleImage").val(menu.middleImage);
                            $("#smallImage").val(menu.smallImage);
                            $("#order").val(menu.order);
                        }
                        else {
                            alert(data.message);
                        }
                    }
                }
            });
        }

        $("#btn_submit").click(function () {
            $('#mainForm').ajaxSubmit({
                    url: '/trainExam/rest/menus' + ($("#id").val() === "" ? "" : "/1"),
                    type: ($("#id").val() === "" ? "post" : "put"),
                    dataType: 'json',
                    success: function (data) {
                        alert(data.message);
                    },
                    clearForm: false,//禁止清楚表单
                    resetForm: false //禁止重置表单
            });

        });
    });

</script>
</body>
</html>